package com.util;
import java.io.*;

public class NameListsParser {

	public static void main(String[] args) {
		for (int i = 0; i < 3; i++) {
			String filename = "";
			String outname = "";
			if (i == 0) {
				filename = "lists/MostCommonMale.htm";
				outname = "lists/male.txt";
			} else if (i == 1) {
				filename = "lists/MostCommonFemale.htm";
				outname = "lists/female.txt";
			} else if (i == 2) {
				filename = "lists/MostCommonSurname.htm";
				outname = "lists/surname.txt";
			}
			
			try{
				BufferedReader in = new BufferedReader(new FileReader(new File(filename)));
				PrintWriter out = new PrintWriter(new File(outname));
				
				String line = in.readLine();
				boolean header = true;
				int count = 0;
				
				while(line != null){
					if(line.startsWith("<tr bgcolor=")){
						if(header){
							header = false;
						}
						else{
							line = line.split("<td>")[1];
							line = line.split("</td>")[0];
							line = line.toLowerCase();
							out.println(line);
							count++;
						}
					}
					line = in.readLine();
				}
				System.out.print(count);
				if(i == 0)
					System.out.println(" male names");
				else if(i == 1)
					System.out.println(" female names");
				else if(i == 2)
					System.out.println(" last names");
				out.flush();
				out.close();
			} catch(IOException e){
				e.printStackTrace();
			}
		}
	}
}
